package com.sad.jetpack.v1.datamodel.api.extension.client.socket.ipc;

import static com.sad.jetpack.v1.datamodel.api.extension.client.socket.ipc.IPCChatDataType.TEXT;

import org.json.JSONObject;


public class IPCChatIntent {

//    public final static int BEGINNING_SEND_MSG =3;//先通过sessionListener发送信息，然后等待监听对方
//    public final static int BEGINNING_RECEIVE_MSG =2;//先等待监听对方，收到信息后再调用sessionListener回调
    //private int workFlowType = BEGINNING_SEND_MSG;//会话发起者的工作流类型（先监听还是先发送内容）
    private IPCChatDataType chatDataType =TEXT;//会话类型
    private String params="";

    public IPCChatDataType getChatDataType() {
        return chatDataType;
    }

    public void setChatDataType(IPCChatDataType chatDataType) {
        this.chatDataType = chatDataType;
    }

//    public int getWorkFlowType() {
//        return workFlowType;
//    }
//
//    public void setWorkFlowType(int workFlowType) {
//        this.workFlowType = workFlowType;
//    }

    public String getParams() {
        return params;
    }

    public void setParams(String params) {
        this.params = params;
    }

    public static IPCChatIntent parse(String s){
        IPCChatIntent intent=new IPCChatIntent();
        try {
            JSONObject json=new JSONObject(s);
            intent=parse(json);
        }catch (Exception e){
            e.printStackTrace();
        }
        return intent;
    }
    public static IPCChatIntent parse(JSONObject json){
        IPCChatIntent intent=new IPCChatIntent();
        try {
            //intent.setWorkFlowType(json.optInt("workFlowType", BEGINNING_SEND_MSG));
            intent.setParams(json.optString("params",""));
            int typeCode=json.optInt("type",0);
            intent.setChatDataType(IPCChatDataType.getChatType(typeCode));
        }catch (Exception e){
            e.printStackTrace();
        }
        return intent;
    }
    public JSONObject toJson(){
        try {
            JSONObject json=new JSONObject();
            //json.put("workFlowType", getWorkFlowType());
            json.put("type", getChatDataType().getTypeCode());
            json.put("params",getParams());
            return json;
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }
}
